<?php
require_once 'common.php';
require_once 'photosaic.php';

$photosaic = new Photosaic();

$response = $photosaic->FlickrCall('flickr.photos.getRecent');
//$response = $photosaic->FlickrCall('flickr.photos.search', array('tags' => 'red', 'sort' => 'date-taken-asc'));

echo	"<link rel='stylesheet' media='screen' href='stylesheet.css' type='text/css' />";

foreach ($response['photos']['photo'] as $photo_num => $photo) {

	$img_url = $photosaic->GetPhotoURL($photo, 's');

	$im = $photosaic->CreateImage($img_url);

	$colors = $photosaic->AnalyzeColors($im);

	echo	"<div class='color' style='background-color:rgb({$colors['avg']['r']},{$colors['avg']['g']},{$colors['avg']['b']})'>".
			"<img src='$img_url'/>".
			"<div class='text'>".
				"Quality ({$colors['quality']['r']}%, {$colors['quality']['g']}%, {$colors['quality']['b']}%) = <b>{$colors['quality']['avg']}%</b><br/>".
				"Average Color ({$colors['avg']['r']}, {$colors['avg']['g']}, {$colors['avg']['b']})".
			"</div>".
		"</div>\n";

	if ($photo_num == 9)
		break;

	unset($rgb);
}

?>